﻿/*
 * This file is part of MonoSettlers.
 *
 * Copyright (C) 2010-2011 Christoph Husse
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors: 
 *      # Christoph Husse
 * 
 * Also checkout our homepage: http://opensettlers.codeplex.com/
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MonoSettlers
{
    internal class PathNodeKey : IQueueItem
    {
        public int X;
        public int Y;
        public long Time;
        public double F { get; set; }
        public double G;
        public double H;
        public int Index { get; set; }
        public int Length { get; set; }

        public static KeyComparer Comparer = new KeyComparer();
        public static KeyComparerIgnoreTime ComparerIgnoreTime = new KeyComparerIgnoreTime();

        public class KeyComparer : IComparer<PathNodeKey>
        {
            public int Compare(PathNodeKey a, PathNodeKey b)
            {
                if (a.X < b.X)
                    return -1;
                else if (a.X > b.X)
                    return 1;

                if (a.Y < b.Y)
                    return -1;
                else if (a.Y > b.Y)
                    return 1;

                // must be the last comparison
                if (a.Time < b.Time)
                    return -1;
                else if (a.Time > b.Time)
                    return 1;

                return 0;
            }
        }

        public class KeyComparerIgnoreTime : IComparer<PathNodeKey>
        {
            public int Compare(PathNodeKey a, PathNodeKey b)
            {
                if (a.X < b.X)
                    return -1;
                else if (a.X > b.X)
                    return 1;

                if (a.Y < b.Y)
                    return -1;
                else if (a.Y > b.Y)
                    return 1;

                return 0;
            }
        }

        public PathNodeKey(int inX, int inY, long inTime)
        {
            F = 0;
            H = 0;
            G = 0;
            X = inX;
            Y = inY;
            Time = inTime;
            Index = -1;
        }

        public override string ToString()
        {
            return 
                "X: " + X.ToString().Padding(3) +
                "; Y: " + Y.ToString().Padding(3) +
                "; Time: " + Time.ToString().Padding(4) +
                "; Length: " + X.ToString().Padding(2);
        }
    }
}
